﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Progresoft.Scheduler.RemoteInterface.Api;
using Progresoft.Scheduler.RemoteInterface;
using Progresoft.Scheduler.RemoteInterface.DataAccess;
using System.Globalization;

public partial class ListSchedules : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			Connector connector = ConnectorManager.GetConnector();
			this.listSchedules.DataBind();
		}
	}

	/// <summary>
	/// Получить строковое предстваление периода запуска
	/// </summary>
	protected string GetExecuteTime(TaskSchedule schedule)
	{
		switch (schedule.ScheduleType)
		{
			case TaskScheduleType.EveryDay:
				return string.Format("{0}, ежедневно", schedule.ExecutionTime.ToShortTimeString());

			case TaskScheduleType.EveryWeek:
				string[] days = ((DateTimeFormatInfo)new CultureInfo("ru-RU").DateTimeFormat).AbbreviatedDayNames;
				string day = days[(int)schedule.ExecutionDayOfWeek.Value];

				return string.Format("{0}, {1}", schedule.ExecutionTime.ToShortTimeString(), day);

			case TaskScheduleType.EveryMonth:
				return string.Format("{0}, каждый {1} день {2} месяца",
					schedule.ExecutionTime.ToShortTimeString(), schedule.ExecutionDayNumber.Value,
					schedule.ExecutionDayIsMonthBegin.Value ? "от начала" : "от конца");

			default:
				return string.Empty;
		}
	}
}
